﻿@{
    ViewBag.Title = "";
    List<DTcms.Model.article_attribute_field> fieldList = ViewBag.fieldList;
    List<DTcms.Model.url_rewrite> urlList = ViewBag.urlList;
}
@model DTcms.Model.site_channel
<form id="form1" class="layui-form" url="ChannelSave?action=@ViewBag.action&id=@ViewBag.id">
    @Html.AntiForgeryToken()
    <!--导航栏-->
    <div class="pageheader">
        <div class="page-bar">
            <ul class="page-breadcrumb">
                <li><a href="../channel/channel_list" class="back"><i class="fa fa-mail-reply-all"></i> 返回列表页</a></li>
                <li><a href="javascript:;"><i class="iconfont icon-home1"></i> 首页</a> </li>
                <li><a href="../channel/channel_list">频道管理</a> </li>
                <li><a href="javascript:;">编辑频道</a> </li>
            </ul>
        </div>
    </div>
    <!--/导航栏-->
    <!--内容-->
    <div class="layui-fluid">
        <div class="layui-tab layui-tab-card">
            <ul class="layui-tab-title" id="floatHead">
                <li class="layui-this">基本信息</li>
                <li>扩展选项</li>
                <li>SEO优化</li>
                <li>URL配置</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <div class="layui-form-item">
                        <label class="layui-form-label">调用名称</label>
                        <div class="layui-input-block">
                            @Html.TextBox("name", Model.name, new { @class = "input normal", datatype = @"/^[a-zA-Z][a-zA-Z0-9\-\_]{1,50}$/", errormsg = "请填写正确的名称！", sucmsg = " " })
                            <span class="Validform_checktip">*调用名称，只允许使用英文、数字或下划线。</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">频道标题</label>
                        <div class="layui-input-block">@Html.TextBox("title", Model.title, new { @class = "input normal", datatype = "*2-100", sucmsg = " " }) <span class="Validform_checktip">*标题备注，允许中文。</span></div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">所属站点</label>
                        <div class="layui-input-block">
                            <select class="select" name="site_id" url="/webapi/siteJson" selectValue="@Model.site_id" promtion="请选择站点..." datatype="*" errormsg="请选择所属站点！" sucmsg=" "><option value="">请选择站点...</option></select>
                            <span class="Validform_checktip">*移动站数据共享，不予显示。</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否启用</label>
                        <div class="layui-input-block">
                            @Html.CheckBox("is_lock", Model.is_lock == 0, new { title = "是" })
                            <span class="Validform_checktip">*是否启用该频道</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">开启专题</label>
                        <div class="layui-input-block">
                            @Html.CheckBox("is_zhuanti", Model.is_zhuanti == 1, new { title = "是" })
                            <span class="Validform_checktip">*开启专题功能后可用于栏目页</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">开启相册</label>
                        <div class="layui-input-block">
                            @Html.CheckBox("is_albums", Model.is_albums == 1, new { title = "是" })
                            <span class="Validform_checktip">*开启相册功能后可上传多张图片</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">开启附件</label>
                        <div class="layui-input-block">
                            @Html.CheckBox("is_attach", Model.is_attach == 1, new { title = "是" })
                            <span class="Validform_checktip">*开启附件功能后可上传多个附件。</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">开启规格</label>
                        <div class="layui-input-block">
                            @Html.CheckBox("is_spec", Model.is_spec == 1, new { title = "是", lay_filter = "spec" })
                            <span class="Validform_checktip">*开启规格需选中市场价、销售价、库存三个扩展字段</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">排序数字</label>
                        <div class="layui-input-block">
                            @Html.TextBox("sort_id", Model.sort_id, new { @class = "input small", datatype = "n", sucmsg = " " })
                            <span class="Validform_checktip">*数字，越小越向前</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">选择字段</label>
                        <div class="layui-input-block">
                            <span id="cblAttributeField">
                                @if (fieldList.Count() > 0)
                                {
                                    foreach (var item in fieldList)
                                    {
                                        if (Model.channel_fields == null)
                                        {
                                            <input id="cblAttributeField_@item.id" name="cblAttributeField_@item.id" title="@item.title" type="checkbox" value="@(item.name + "," + item.id)" lay-filter="field" />
                                        }
                                        else
                                        {
                                            <input id="cblAttributeField_@item.id" name="cblAttributeField_@item.id" title="@item.title" type="checkbox" value="@(item.name + "," + item.id)" @(Model.channel_fields.Find(p => p.field_id == item.id) != null ? "checked" : "") lay-filter="field" />
                                        }
                                    }
                                }
                            </span>
                        </div>
                    </div>
                </div>
                <div class="layui-tab-item">
                    <div class="layui-form-item">
                        <label class="layui-form-label">开启评论</label>
                        <div class="layui-input-block">
                            @Html.CheckBox("is_comment", Model.is_comment == 1, new { title = "是" })
                            <span class="Validform_checktip">*开启商品评论功能</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">开启回收站</label>
                        <div class="layui-input-block">
                            @Html.CheckBox("is_recycle", Model.is_recycle == 1, new { title = "是" })
                            <span class="Validform_checktip">*开启内容回收站</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">开启自定义参数</label>
                        <div class="layui-input-block">
                            @Html.CheckBox("is_attribute", Model.is_attribute == 1, new { title = "是" })
                            <span class="Validform_checktip">*开启商品自定义参数</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">默认展现方式</label>
                        <div class="layui-input-block">
                            @Html.RadioButton("is_type", 0, Model.is_type == 0, new { title = "图文" })
                            @Html.RadioButton("is_type", 1, Model.is_type == 1, new { title = "列表" })
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">自定义图片尺寸</label>
                        <div class="layui-input-block">
                            <table border="0" cellspacing="0" cellpadding="0" class="border-table" width="100%">
                                <thead>
                                    <tr>
                                        <th width="100" style="text-align:left;">名称</th>
                                        <th width="300" style="text-align:left;">生成类型</th>
                                        <th width="130" style="text-align:left;">宽(单位:px)</th>
                                        <th width="130" style="text-align:left;">高(单位:px)</th>
                                        <th style="text-align:left;">是否启用</th>
                                    </tr>
                                </thead>
                                <tbody id="thumTbody" class="tstbody">
                                    @{
                                        int i = 0;
                                        foreach (var item in Model.channel_thums)
                                        {
                                            i++;
                                            <tr>
                                                <td>
                                                    @Html.Hidden("hidId_" + i, item.id)
                                                    @Html.Hidden("hidTypeId_" + i, item.typeid)
                                                    @Html.Hidden("hidIsLock_" + i, item.is_lock)
                                                    @Html.Hidden("hidClassId_" + i, item.class_id)
                                                    @Html.Hidden("hidTitle_" + i, item.title)
                                                    <span>@item.title</span>
                                                </td>
                                                <td>
                                                    @Html.RadioButton("type_id_" + i, 0, item.typeid == 0, new { title = "裁剪" })
                                                    @Html.RadioButton("type_id_" + i, 1, item.typeid == 1, new { title = "补白" })
                                                    @Html.RadioButton("type_id_" + i, 2, item.typeid == 2, new { title = "等比" })
                                                    @Html.RadioButton("type_id_" + i, 3, item.typeid == 3, new { title = "限宽" })
                                                    @Html.RadioButton("type_id_" + i, 4, item.typeid == 4, new { title = "限高" })
                                                </td>
                                                <td>@Html.TextBox("Width_" + i, item.width, new { @class = "input small", datatype = "n", sucmsg = " " })</td>
                                                <td>@Html.TextBox("Height_" + i, item.height, new { @class = "input small", datatype = "n", sucmsg = " " })</td>
                                                <td>
                                                    @Html.CheckBox("is_lock_" + i, item.is_lock == 1, new { title = "是" })
                                                </td>
                                            </tr>
                                        }
                                    }
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
                <div class="layui-tab-item">
                    <div class="layui-form-item">
                        <label class="layui-form-label">SEO标题</label>
                        <div class="layui-input-block">
                            @Html.TextBox("seo_title", Model.seo_title, new { @maxlength = "255", @class = "input normal", datatype = "*0-100", sucmsg = " " })
                            <span class="Validform_checktip">255个字符以内</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">SEO关健字</label>
                        <div class="layui-input-block">
                            @Html.TextArea("seo_keywords", Model.seo_keywords, new { @class = "input multiline", datatype = "*0-255", sucmsg = " " })
                            <span class="Validform_checktip">以“,”逗号区分开，255个字符以内</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">SEO描述</label>
                        <div class="layui-input-block">
                            @Html.TextArea("seo_description", Model.seo_description, new { @class = "input multiline", datatype = "*0-255", sucmsg = " " })
                            <span class="Validform_checktip">255个字符以内</span>
                        </div>
                    </div>
                </div>
                <div class="layui-tab-item">
                    <div class="layui-form-item">
                        <label class="layui-form-label">URL生成配置</label>
                        <div class="layui-input-block"><a id="itemAddButton" class="layui-btn layui-btn-primary icon-btn"><i class="iconfont icon-add"></i> 添加页面</a></div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"></label>
                        <div class="layui-input-block">
                            <div class="table-container">
                                <table border="0" cellspacing="0" cellpadding="0" class="border-table" width="100%">
                                    <thead>
                                        <tr>
                                            <th width="12%">类型</th>
                                            <th width="16%">调用名称</th>
                                            <th width="20%">生成文件名</th>
                                            <th width="20%">模板文件名</th>
                                            <th width="12%">分页大小</th>
                                            <th width="10%">操作</th>
                                        </tr>
                                    </thead>
                                    <tbody id="item_box">
                                        @{
                                            if (urlList != null)
                                            {
                                                foreach (DTcms.Model.url_rewrite item in urlList)
                                                {
                                                    <tr class="td_c">
                                                        <td>
                                                            <input type="hidden" name="item_rewrite" value="@item.url_rewrite_str" />
                                                            <input type="hidden" name="item_type" value="@item.type" />
                                                            <span class="item_type">
                                                                @switch (item.type)
                                                                {
                                                                    case "index":
                                                                        @:首页
                                                                        break;
                                                                    case "category":
                                                                        @:栏目页
                                                                        break;
                                                                    case "list":
                                                                        @:列表页
                                                                        break;
                                                                    case "detail":
                                                                        @:详细页
                                                                        break;
                                                                    case "other":
                                                                        @:其他页
                                                                        break;
                                                                }
                                                            </span>
                                                        </td>
                                                        <td>
                                                            <input type="hidden" name="old_item_name" value="@item.name" />
                                                            <input type="hidden" name="item_name" value="@item.name" />
                                                            <span class="item_name">@item.name</span>
                                                        </td>
                                                        <td>
                                                            <input type="hidden" name="item_page" value="@item.page" />
                                                            <span class="item_page">@item.page</span>
                                                        </td>
                                                        <td>
                                                            <input type="hidden" name="item_templet" value="@item.templet" />
                                                            <span class="item_templet">@item.templet</span>
                                                        </td>
                                                        <td>
                                                            <input type="hidden" name="item_pagesize" value="@item.pagesize" />
                                                            <span class="item_pagesize">@(item.pagesize.ToString() != "" ? item.pagesize : "-")</span>
                                                        </td>
                                                        <td>
                                                            <a title="编辑" class="img-btn" onclick="showChannelDialog(this);"><i class="iconfont icon-edit"></i></a>
                                                            <a title="删除" class="img-btn" onclick="delItemTr(this);"><i class="iconfont icon-delete"></i></a>
                                                        </td>
                                                    </tr>
                                                }
                                            }
                                        }
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--/内容-->
    <!--工具栏-->
    <div class="page-footer">
        <div class="btn-wrap">
            <button class="layui-btn icon-btn" id="btnSubmit"><i class="layui-icon layui-icon-ok"></i>提交保存</button>
            <button class="layui-btn layui-btn-warm icon-btn" name="btnReturn" onclick="javascript:history.back(-1);"><i class="layui-icon layui-icon-return"></i>返回上一页</button>
        </div>
    </div>
    <!--/工具栏-->
</form>
@section Scripts{
    <script type="text/javascript">
        layui.use(['validform', 'element', 'jqueryform', 'cascadeSelect', 'form'], function () {
            var cascadeSelect = layui.cascadeSelect, form = layui.form;
            cascadeSelect.init('site_id', false);

            //初始化表单验证
            $("#form1").initValidform('#btnSubmit', 1);

            //添加按钮(点击绑定)
            $("#itemAddButton").click(function () {
                showChannelDialog();
            });

            //关联规格相关字段
            var objMarketPrice;
            var objSellPrice;
            var objStockQuantity; //声明对象
            $("#cblAttributeField input").each(function () {
                var fieldArr = $(this).val().split(',');
                var fieldIndex = $("#cblAttributeField input[type=checkbox]").index($(this));
                if (fieldArr[0] == 'market_price') {
                    objMarketPrice = $("#cblAttributeField input[name=cblAttributeField_" + fieldArr[1] + "]");
                }
                if (fieldArr[0] == 'sell_price') {
                    objSellPrice = $("#cblAttributeField input[name=cblAttributeField_" + fieldArr[1] + "]");
                }
                if (fieldArr[0] == 'stock_quantity') {
                    objStockQuantity = $("#cblAttributeField input[name=cblAttributeField_" + fieldArr[1] + "]");
                }
            });
            form.on('checkbox(spec)', function (data) {
                if (data.elem.checked) {
                    if (!$(objMarketPrice).prop('checked')) {
                        objMarketPrice.trigger("click");
                    }
                    if (!$(objSellPrice).prop('checked')) {
                        objSellPrice.trigger("click");
                    }
                    if (!$(objStockQuantity).prop('checked')) {
                        objStockQuantity.trigger("click");
                    }
                }
                form.render("checkbox");
            });
            form.on('checkbox(field)', function (data) {
                var value = data.value, checked = data.elem.checked, spec = $("#is_spec").prop("checked");
                var fieldArr = value.split(',');
                switch (fieldArr[0]) {
                    case 'market_price':
                        if (!checked && spec) {
                            $("#is_spec").trigger("click");
                        }
                        break;
                    case 'sell_price':
                        if (!checked && spec) {
                            $("#is_spec").trigger("click");
                        }
                        break;
                    case 'stock_quantity':
                        if (!checked && spec) {
                            $("#is_spec").trigger("click");
                        }
                        break;
                }
                form.render("checkbox");
            });

            //创建窗口
            window.showChannelDialog =function(obj) {
                var objNum = arguments.length;
                var d = layer.open({
                    type: 2,
                    area: ['800px', '600px'],
                    title: "URL配置信息",
                    maxmin: true,
                    content: '../dialog/dialog_channel',
                    btn: ["确定", '关闭'],
                    btn1: function (index, layero) {
                        var iframeWin = window[layero.find('iframe')[0]['name']];
                        var trHtml = iframeWin.submitForm(obj);
                        if (trHtml.length > 0) {
                            $("#item_box").append(trHtml);
                            layer.close(index);
                        }
                    },
                    success: function (layero, index) {
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']];
                        //检查是否修改状态
                        if (objNum == 1) {
                            iframeWin.submitValue(obj);
                        }
                    },
                    cancel: function (index, layero) { }
                });
            }

            //删除一行
            window.delItemTr= function(obj) {
                layer.confirm('您确定要删除这个页面吗？', { icon: 3, title: '提示' }, function (index) {
                    $(obj).parent().parent().remove(); //删除节点
                    layer.close(index);
                });
            }
        });
    </script>
}